﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Solution
{
    public static class ValidateHelper
    {
        #region 公共方法

        /// <summary>
        /// 验证是否为E-mail
        /// </summary>
        /// <param name="str_Email"></param>
        /// <returns></returns>
        public static bool IsEmail(this string str_Email)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(str_Email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
        }

        /// <summary>
        /// 验证是否为手机号码
        /// </summary>
        /// <param name="phoneStr"></param>
        /// <returns></returns>
        public static bool IsMobilPhone(this string phoneStr)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(phoneStr, @"^1[3|4|5|7|8][0-9]\d{4,8}$");
        }

        /// <summary>
        /// 验证是否符合价格格式
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsMoney(this string input)
        {
            Regex regex = new Regex(@"^(0|([1-9]\d*))(\.\d+)?$");
            return regex.IsMatch(input);
        }

        /// <summary>
        /// 验证是否为数字
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsNumber(this string input)
        {
            Regex regex = new Regex("^[0-9]*[1-9][0-9]*$");
            return regex.IsMatch(input);
        }

        #endregion 公共方法
    }
}